package web;

import pojo.SmbmsBill;
import service.SmbmsBillService;
import service.impl.SmbmsBillServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(value = "/billView")
public class ShowBillServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
            ServletException, IOException {
        this.doPost(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    //从页面获取ID
        req.setCharacterEncoding("UTF-8");
        String id=req.getParameter("id");
        Long ids=0L;
        if(id != null){
            ids=Long.parseLong(id);
        }
    //调用业务层接口
        //账单数据
        SmbmsBillService smbmsBillService=new SmbmsBillServiceImpl();
        //供应商数据(待编写）


        try {
            SmbmsBill smbmsBill = smbmsBillService.queryBillById(ids);
            if(null != smbmsBill){
    //把对象放在request作用域中
                req.setAttribute("bill",smbmsBill);
                //供应商数据（待编写）


                req.getRequestDispatcher("BillView.jsp").forward(req,resp);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
